package com.ruoyi.logistic.service.impl;

import com.github.pagehelper.PageHelper;
import com.ruoyi.common.domain.vo.TableVo;
import com.ruoyi.hqfinance.domain.HqSolicitor;
import com.ruoyi.hqfinance.domain.HqTransferCentre;
import com.ruoyi.hqfinance.mapper.HqSolicitorMapper;
import com.ruoyi.hqfinance.mapper.HqTransferCentreMapper;
import com.ruoyi.logistic.domain.NetworkClient;
import com.ruoyi.logistic.domain.NetworkName;
import com.ruoyi.logistic.domain.NetworkWeightDifference;
import com.ruoyi.logistic.domain.PageInfo;
import com.ruoyi.logistic.domain.vo.NetworkWeightDifferenceVo;
import com.ruoyi.logistic.enums.NetworkWeightDifferenceEnum;
import com.ruoyi.logistic.enums.SettleTypeEnum;
import com.ruoyi.logistic.enums.SettleWeightSourceEnum;
import com.ruoyi.logistic.mapper.NetworkClientMapper;
import com.ruoyi.logistic.mapper.NetworkNameMapper;
import com.ruoyi.logistic.mapper.NetworkWeightDifferenceMapper;
import com.ruoyi.logistic.service.NetworkWeightDifferenceService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

@Service
public class NetworkWeightDifferenceServiceImpl implements NetworkWeightDifferenceService {
    @Autowired
    private NetworkWeightDifferenceMapper networkWeightDifferenceMapper;
    @Autowired
    private HqTransferCentreMapper hqTransferCentreMapper;
    @Autowired
    private NetworkClientMapper networkClientMapper;
    @Autowired
    private NetworkNameMapper networkNameMapper;
    @Autowired
    private HqSolicitorMapper hqSolicitorMapper;

    @Override
    public List<NetworkWeightDifference> selectList(NetworkWeightDifferenceVo networkWeightDifferenceVo) {
        //添加分页查询
        PageHelper.startPage(networkWeightDifferenceVo.getPageDate());
        return networkWeightDifferenceMapper.selectList(networkWeightDifferenceVo);
    }

    @Override
    public List<HqTransferCentre> settleByName(String name) {
        return hqTransferCentreMapper.selectByName(name);
    }

    @Override
    public List<HqTransferCentre> selectAll() {
        return hqTransferCentreMapper.selectAll();
    }

    @Override
    public List<NetworkClient> selectByName(String name) {
        if (name == null){
            return networkClientMapper.selectAll();
        }else {
            return networkClientMapper.selectByName(name);
        }
    }

    @Override
    public List<NetworkName> selectByNetName(String name) {
        if (name == null){
            return networkNameMapper.selectAll();
        }else {
            return networkNameMapper.selectByName(name);
        }
    }

    @Override
    public List<HqSolicitor> selectBySolName(String name) {
        if (name == null) {
            return hqSolicitorMapper.selectAll();
        } else {
            return hqSolicitorMapper.selectByName(name);
        }
    }

    @Override
    public List<TableVo> initTable() {
        List<TableVo> list = new ArrayList<>();
        TableVo tableVo = new TableVo();
        String[] fields = {"settlementTime","transportCode","networkNameId","leaveCenter","settleType","settleObject"
                ,"packageCode","networkWeight","settleWeightSource","settleWeight","settleNetworkWeight","centreWeight"
                , "centerNetworkWeight","volumeWeight","hqSettleWeight"};
        for (String field : fields) {
            tableVo = new TableVo();
            tableVo.setFields(field);
            list.add(tableVo);
        }
        for (TableVo vo : list) {
            vo.setTranslate(NetworkWeightDifferenceEnum.getValue(vo.getFields()));
        }
        return list;
    }
}
